define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    table: 'order'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
				searchFormVisible: true,
				columns: [
                    [
                        {field: 'state', checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'company', title: __('公司名称'), operate: 'LIKE'},
                        {field: 'content', title: __('服务内容'), operate: 'LIKE', align:'left', width:'50%', cellStyle:function(value, row, index){
							return {css:{"white-space": "normal"}};
						}},
						{field: 'timeline', title: __('服务时间'), formatter: Table.api.formatter.datetime, datetimeFormat:'YYYY-MM-DD', operate: 'RANGE', addclass: 'datetimerange', sortable: true},
						{field: 'leader', title: __('负责人'), operate: 'LIKE'},
                        {field: 'admin_id', title: __('录入人'), addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'", formatter:function(value, row, index){
							return row.admin.nickname;
						}},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
				$(document).on('click','button[type="reset"]', function(){
					var index = parent.Layer.getFrameIndex(window.name);
					parent.Layer.close(index);
				});
			
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
